package com.zone.vehicle.superapp.repository;

import android.content.Context;

import com.saicmotor.pay.db.entity.Pay;
import com.zone.lib.download.enums.AppStatusEnum;
import com.zone.sdk.common.http.base.PageResult;
import com.zone.sdk.common.http.base.Result;
import com.zone.sdk.common.http.callback.ResultCallBack;
import com.zone.sdk.module.appstore.base.AppStoreResult;
import com.zone.sdk.module.appstore.entity.AppDetailEntity;
import com.zone.sdk.module.appstore.entity.AppEntity;
import com.zone.sdk.module.appstore.entity.AppListItemEntity;
import com.saicmotor.pay.entity.OrderEntity;
import com.zone.sdk.module.appstore.entity.UserEntity;
import com.zone.sdk.module.comment.base.CommentPage;
import com.zone.sdk.module.comment.entity.AppCommentScoreEntity;
import com.zone.sdk.module.comment.entity.CommentListEntity;
import com.zone.sdk.module.comment.entity.RecommendEntity;
import com.zone.sdk.module.comment.entity.RecommendListEntity;
import com.zone.sdk.module.comment.entity.SearchResultEntity;
import com.zone.vehicle.sdk.module.superapp.response.AppPushResponse;
import com.zone.vehicle.superapp.datasource.HomeDataSource;

import java.util.List;

/**
 * Class that requests authentication and user information from the remote data source and
 * maintains an in-memory cache of login status and user credentials information.
 */
public class HomeRepository {

    private static volatile HomeRepository instance;

    private HomeDataSource dataSource;

    private HomeRepository(HomeDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public static HomeRepository getInstance(HomeDataSource dataSource) {
        if (instance == null) {
            instance = new HomeRepository(dataSource);
        }
        return instance;
    }

    public void indexSearch(String search, ResultCallBack<Result<CommentPage<SearchResultEntity>>> callback){
        dataSource.indexSearch(search, callback);
    }

    public void getHomeAppListData(int pageNo, int pageSize, ResultCallBack<Result<AppStoreResult<AppListItemEntity>>> callback) {
        dataSource.getHomeAppListData(pageNo, pageSize, callback);
    }

    public void getAppDetail(Context context, String code, ResultCallBack<Result<AppDetailEntity>> callback) {
        dataSource.getAppDetail(context, code, callback);
    }

    public void appList(List<String> codeList, ResultCallBack<Result<List<AppEntity>>> callBack){
        dataSource.appList(codeList, callBack);
    }

    public void submitOrder(Context context, String source, AppDetailEntity app, UserEntity user, ResultCallBack<Result<OrderEntity>> callBack){
        dataSource.submitOrder(context, source, app, user, callBack);
    }

    public void commentList(String code, ResultCallBack<Result<CommentListEntity>> callback) {
        dataSource.commentList(code, callback);
    }

    public void commentInitAmwayWallList(ResultCallBack<Result<RecommendListEntity>> callback) {
        dataSource.commentInitAmwayWallList(callback);
    }

    /**
     * 安利墙：根据appids批量获取app信息
     * @param callback
     */
    public void getRecommendListApp(ResultCallBack<Result<PageResult<RecommendEntity>>> callback) {
        dataSource.getRecommendListApp(1, 10, callback);
    }

    public void commentScore(String objectId, ResultCallBack<Result<AppCommentScoreEntity>> callback){
        dataSource.commentScore(objectId, callback);
    }

    public void downLoadApp(Context context, int status, AppDetailEntity appEntity){
        dataSource.downLoadApp(context, status, appEntity);
    }

    public void appletPush(Context context, AppDetailEntity appEntity, AppStatusEnum statusEnum, ResultCallBack<Result<AppPushResponse>> callback){
        dataSource.appletPush(context, appEntity, statusEnum, callback);
    }

    public void install(Context context, AppDetailEntity appEntity, AppStatusEnum statusEnum){
        dataSource.install(context, appEntity, statusEnum);
    }

    public List<Pay> listPay(){
        return dataSource.listPay();
    }

}